package com.nervenets.web.redis.domain;

import com.nervenets.web.hibernate.domain.Building;
import com.nervenets.web.redis.RedisSetDomain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BuildingStored extends RedisSetDomain {
    private long buildingId;
    private String name;
    private String cover;

    @Override
    public String getField() {
        return String.valueOf(buildingId);
    }

    @Override
    public String getKey() {
        return String.format("B_V1_%s", String.format("%04d", buildingId).substring(0, 4));
    }

    public BuildingStored(long buildingId) {
        this.buildingId = buildingId;
    }

    public BuildingStored(Building building) {
        this.buildingId = building.getId();
        this.name = building.getName();
        this.cover = building.getCover();
    }
}
